package com.wfk.service.impl;

import com.wfk.entity.ReceivedAddr;
import com.wfk.mapper.ReceivedAddrMapper;
import com.wfk.service.IReceivedAddrService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户收货地址表 服务实现类
 * </p>
 *
 * @since 2019-01-07
 */
@Service
public class ReceivedAddrServiceImpl extends ServiceImpl<ReceivedAddrMapper, ReceivedAddr> implements IReceivedAddrService {
	@Override
	public void upDefault(Integer cid) {
		QueryWrapper<ReceivedAddr> queryWrapper = new QueryWrapper<ReceivedAddr>();
		queryWrapper.eq("cid", cid);
		queryWrapper.eq("isdefault",0);
		ReceivedAddr entity = super.getOne(queryWrapper);
		if(entity!=null){
			entity.setIsdefault(-1);
			super.updateById(entity);
		}
	}
	
	@Override
	public ReceivedAddr getDefault(Integer cid) {
		QueryWrapper<ReceivedAddr> queryWrapper = new QueryWrapper<ReceivedAddr>();
		queryWrapper.eq("cid", cid);
		queryWrapper.eq("isdefault",0);
		ReceivedAddr entity = super.getOne(queryWrapper);
		return entity;
	}
}
